package com.itheima.category.controller;

import com.itheima.category.service.CategoryService;
import com.itheima.goods.pojo.Category;
import entity.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/category")

public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    @GetMapping
    public Result findAll(){
        return categoryService.findAll() ;
    }
    @PostMapping
    public Result add(@PathVariable("category") Category category){
        return categoryService.add(category);
    }

    @GetMapping("/search/{page}/{size}")
    public Result findPage(@PathVariable("page") Integer page,@PathVariable("size") Integer size){
        return categoryService.findPage(page,size);
    }

    @GetMapping("/{id}")
    public Result findById(@PathVariable("id") Integer id){
        return categoryService.findById(id);
    }
    @PutMapping("/{id}")
    public Result update(@PathVariable("id") Integer id,@PathVariable("category") Category category){
        return categoryService.update(id, category);

    }
  @DeleteMapping("/{id}")
    public Result update(@PathVariable("id") Integer id){
        return categoryService.delete(id);

    }




}
